#!/usr/bin/python
# -*- coding: utf-8 -*-
# @version        : 1.0
# @Create Time    : 2024-07-17 16:17
# @File           : issue.py
# @IDE            : PyCharm
# @desc           : 常见问题


from fastapi import Depends

from application.settings import CONFIG
from core.dependencies import Paging, QueryParams


class TaskParams(QueryParams):
    """
    列表分页
    """

    def __init__(
            self,
            params: Paging = Depends(),
            ao_id: str = None,
            ao_name: str = None,
            ao_type: str = None,
            product_type: str = None,
            flight: str = None,
            station: str = None,
            position: str = None,
            team: str = None,
            status: str = None,
            group_id: str = None,
            ticket_id: str = None,
            team_leader: str = None,
            plan_user: str = None,
            plan_start: str = None,
            plan_end: str = None,
            start: str = None,
            end: str = None,
            is_not_assign: bool = None,
    ):
        super().__init__(params)
        self.ao_id = ("like", ao_id)
        self.ao_name = ("like", ao_name)
        self.ao_type = ao_type

        self.product_type = product_type
        self.flight = flight 
        self.station = station
        self.position = position

        self.team = team
        if team_leader:
            self.team_leader = ("like", team_leader)

        self.status = status
        self.ticket_id = ticket_id

        if plan_user:
            self.plan_user = ("like", plan_user)
        if plan_start:
            self.plan_start = ('between', plan_start.split(","))
        if plan_end:
            self.plan_end = ('between', plan_end.split(","))

        if start:
            self.start = ('between', start.split(","))
        if end:
            self.end = ('between', end.split(","))
        
        if group_id:
            group_values = [i if i else None for i in group_id.split("|")]
            group_keys = CONFIG.DISPATCH.TASK_GROUP_KEY
            for i, value in enumerate(group_values):
                if value and value != "UKN":
                    setattr(self, group_keys[i], value)
                elif value == "UKN":
                    setattr(self, group_keys[i], ('None',))

        self.is_not_assign = is_not_assign

        self.v_order_field = CONFIG.DISPATCH.TASK_ORDER_KEY
        self.v_order = "asc"


class TaskGroupParams(QueryParams):
    """
    列表分页
    """

    def __init__(
            self,
            product_type: str = None,
            flight: str = None,
            station: str = None,
            position: str = None,
    ):
        super().__init__()
        self.product_type = product_type
        self.flight = flight
        self.station = station
        self.position = position


class TaskQueryParams(QueryParams):
    """
    列表分页
    """

    def __init__(
            self,
            ticket_id: str = None
    ):
        super().__init__()
        if ticket_id:
            self.ticket_id = ("like", ticket_id)
